Select a single file using OpenFileDialog
C# .NET |
public static string DoTest() { System.Windows.Forms.OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\" ; openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ; openFileDialog1.FilterIndex = 1 ; openFileDialog1.RestoreDirectory = true ; String strRet = "Selected Files(s):\r\n"; if(openFileDialog1.ShowDialog() == DialogResult.OK) { strRet += openFileDialog1.FileName; } return strRet; } |
Blaze++ .NET |
static String DoTest() { System::Windows::Forms::OpenFileDialog openFileDialog1; openFileDialog1.InitialDirectory = "c:\\" ; openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ; openFileDialog1.FilterIndex = 1 ; openFileDialog1.RestoreDirectory = true ; String strRet = "Selected File: "; if(openFileDialog1.ShowDialog() == DialogResult::OK) { strRet += openFileDialog1.FileName; } return strRet; } |